package com.newbingo.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.criterion.Expression;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.newbingo.dao.imple.IPerviewDao;
import com.newbingo.entity.Perview;

/*
 * 权限DAO
 */
public class PerviewDao extends HibernateDaoSupport implements IPerviewDao {
	private static final Log log=LogFactory.getLog(PerviewDao.class);
	
	/* (non-Javadoc)
	 * @see com.newbingo.dao.IPerviewDao#findById(java.lang.Integer)
	 */
	public Perview findById(Integer id){
		log.debug("finding Perview instance by id");
		try{
			Perview perview=(Perview)getSession().get(Perview.class, id);
			return perview;
		}catch(RuntimeException re){
			log.error("find failed");
			throw re;
		}
	}
	
	/*
	 * 根据根权限查询出权限和子权限
	 */
	/* (non-Javadoc)
	 * @see com.newbingo.dao.IPerviewDao#findAll()
	 */
	public List findAll(){
		log.debug("find Perview instance and sub Perview instance");
		try{
			Criteria cri=getSession().createCriteria(Perview.class);
			cri.add(Expression.isNull("parentPerview"));
			cri.setResultTransformer(Criteria.ROOT_ENTITY);
			return (List<Perview>)cri.list();
		}catch(RuntimeException re){
			log.error("find failed");
			throw re;
		}
	}
	

}
